package com.lgr.store.service;

import org.springframework.stereotype.Service;

import com.lgr.store.dao.CharactersDAO;
import com.lgr.store.utils.PageObject;
import com.lgr.store.vo.CharEmpVo;
import com.lgr.store.vo.CharactersVo;
import com.lgr.store.vo.CharmoduleVo;
import com.lgr.store.vo.EmpVo;
import com.lgr.store.vo.ModuleVo;

import javax.annotation.Resource;
import java.util.List;
// 权限设置
@Service
public class CharactersService {
    @Resource
    private CharactersDAO charactersDAO;
    
    public void save(CharactersVo characters){
        if(characters.getCharacterId()!=null){
            charactersDAO.update(characters);
        }else {
            charactersDAO.save(characters);
        }
    }
    public void del(int charactersId){
        charactersDAO.delCharmodule(charactersId);
        charactersDAO.delCharEmp(charactersId);
        charactersDAO.del(charactersId);
    }
    public List<CharactersVo> list(PageObject pager){
        return charactersDAO.list(pager);
    }
    public int getCount(){
        return charactersDAO.getCount();
    }
    public CharactersVo getById(int characterId){

        return charactersDAO.getById(characterId);
    }
    //查询所有系统权限
    public List<ModuleVo> selectModule(){
        return charactersDAO.selectModule();
    }
    //查询角色权限
    public List<CharmoduleVo> selectCharmodule(int characterId){
        return charactersDAO.selectCharmodule(characterId);
    }
    //保存权限设置
    public void saveCharmodule(List<CharmoduleVo> list,int characterId){
        charactersDAO.delCharmodule(characterId);
        if(list.size()!=0){
        	for (CharmoduleVo charmoduleVo : list) {
        		charactersDAO.saveCharmodule(charmoduleVo);
			}
        }
    }
    //保存用户授权设置
    public void saveCharEmp(List<CharEmpVo> list,int characterId){
        charactersDAO.delCharEmp(characterId);
        if(list.size()!=0){
            for(CharEmpVo emp:list)
            {
                charactersDAO.saveCharEmp(emp);
            }
        }
    }
    //查找用户
    public List<EmpVo> findEmpDep(){

        return charactersDAO.findEmpDep();
    }
    public List<CharEmpVo> findCharEmp (int characterId,int empId){

        return charactersDAO.findCharEmp(characterId,empId);
    }
    //获取用户权限
    public List<ModuleVo> findEmpChar(String empId){

        return charactersDAO.findEmpChar(empId);
    }
    public  List<ModuleVo> findModule(){

        return charactersDAO.findModule();
    }

}
